﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LifeSoftLibary;
using System.Text.RegularExpressions;
using LifeSoft.Controller;
using LifeSoft.BusinessObject;
using LifeSoft.GUI.usrControl;

namespace LifeSoft.GUI
{
    public partial class frmLogin : Form
    {
        private SysLogLoginInfo loginInfo;
        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            
        }

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            //base.OnFormClosing(e);
            //if (e.CloseReason == CloseReason.MdiFormClosing) return;
            //    frmMain main = new frmMain();
            //    main.showSetupFirstBase();
        }

        private MetrolBillCommands _Commands;
        public MetrolBillCommands Commands
        {
            get { return _Commands; }
            set 
            {
                if (value != _Commands)
                {
                    MetrolBillCommands oldValue = _Commands;
                    _Commands = value;
                }
            }
        }

        private void btForgotPassword_Click(object sender, EventArgs e)
        {
            frmForgotPassword frm = new frmForgotPassword();
            frm.ShowDialog();
        }

        private void btLogin_Click(object sender, EventArgs e)
        {
            loginInfo = new SysLogLoginInfo();
            string userName = txtUserName.Text;
            string password = txtPassword.Text;
            string _password = EncryptMD5.GetMD5Hash(password);
            loginInfo.userName = userName;
            loginInfo.password = _password;
            LoginCtr loginCtr = new LoginCtr();
            Boolean checkLogin = loginCtr.getSysUserLogin(loginInfo);
            if (checkLogin == true)
            {
                this.Close();
                frmMain main = new frmMain();
                main.login_success();
//                main.frmMain_Load(sender, e);
                
            }
            else
            {
                MessageBox.Show("Tên đăng nhập hoặc mật khẩu không tồn tại!");
            }
        }
    }
}
